package EBM.BLL;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import EBM.DB.BugDAO;
import EBM.DB.BugLogDAO;
import EBM.DB.BugUserDAO;
import EBM.model.Bug;
import EBM.model.BugLog;
import EBM.model.BugUser;
import EBM.model.User;
import EBM.util.SystemTime;

public class BugManage implements EBMConstant {
	private Bug bug;
	private BugUser bugUser;
	private BugLog bugLog;
	private List<Object> tmp;
	private List<Object> response;
	private BugDAO bugDAO;
	private BugLogDAO bugLogDAO;
	private BugUserDAO bugUserDAO;

	// 查找缺陷的信息
	protected Bug FindBug(String proid, String bugid) throws SQLException,
			ClassNotFoundException {

		bugDAO = new BugDAO();
		Bug bug = bugDAO.findById(proid, bugid);
		return bug;
	}

	// 查找缺陷的日志
	public List<Object> FindBugLog(List<Object> request) throws SQLException,
			ClassNotFoundException {

		String proid = request.get(0).toString();
		String bugid = request.get(1).toString();
		bugid = EBM.util.BugID.ConvertFromClientToServer(bugid);

		bugLogDAO = new BugLogDAO();

		tmp = bugLogDAO.findByBugid(proid, bugid);
		response = new ArrayList<Object>();

		Iterator<Object> iter = tmp.iterator();
		while (iter.hasNext()) {
			BugLog bl = (BugLog) iter.next();
			response.add(bl.getTime());
			response.add(bl.getPerson());
			response.add(bl.getDetail());
		}
		if (tmp.size() < 1)
			response.add("-1");

		return response;
	}

	// 查找缺陷列表 无条件
	public List<Object> FindBugListByProid(List<Object> request)
			throws SQLException, ClassNotFoundException, ParseException {

		response = new ArrayList<Object>();

		String proid = request.get(0).toString();

		BugDAO bugDAO = new BugDAO();
		tmp = bugDAO.findByProid(proid);

		bugUserDAO = new BugUserDAO();

		Iterator<Object> iter = tmp.iterator();
		while (iter.hasNext()) {
			Bug b = (Bug) iter.next();

			response.add(EBM.util.BugID.ConvertFromServerToClient(b.getId()));

			// 当前责任人
			User user = new User();
			user = bugUserDAO.findByBugid(proid, b.getId(), usr_responsible);
			response.add(user.getUsrid());
			response.add(user.getName());

			response.add(b.getBug_statu());

			if (b.getSimple_description() != null)
				response.add(b.getSimple_description()); // 概要描述
			else
				response.add("-1");

			// 停留天数
			String days = SystemTime.WaitingDays(b.getCurrent_step_time());
			response.add(days);
		}
		if (tmp.size() <= 0)
			response.add("-1");

		return response;
	}

	// 查找缺陷列表
	public List<Object> FindBugList(List<Object> request) throws SQLException,
			ClassNotFoundException, ParseException {

		bug = new Bug();
		bugUser = new BugUser();
		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));
		bugUser.setUsr_submit(request.get(2).toString());
		bugUser.setUsr_responsible(request.get(3).toString());
		bug.setBug_statu(request.get(4).toString());
		bug.setBug_model(request.get(5).toString());
		bug.setSerious_level(request.get(6).toString());
		bug.setStartTime(request.get(7).toString());
		bug.setEndTime(request.get(8).toString());

		// 缺陷信息
		BugDAO bugDAO = new BugDAO();
		BugUserDAO bugUserDAO = new BugUserDAO();
		User user = new User();
		response = new ArrayList<Object>();
		tmp = bugDAO.findByCertainProperty(bug.getProid(), bug, bugUser);

		Iterator<Object> iter = tmp.iterator();
		while (iter.hasNext()) {
			Bug b = (Bug) iter.next();

			// bug id
			response.add(EBM.util.BugID.ConvertFromServerToClient(b.getId()));
			// 当前责任人
			user = bugUserDAO.findByBugid(bug.getProid(), b.getId(), usr_responsible);
			response.add(user.getUsrid());
			response.add(user.getName());

			response.add(b.getBug_statu());
			response.add(b.getSimple_description());

			// 停留天数
			String days = SystemTime.WaitingDays(b.getCurrent_step_time());
			response.add(days);
		}
		if (tmp.size() < 1)
			response.add("-1");

		return response;
	}

	// 查找缺陷列表
	// precondition: 用户为缺陷的当前责任人
	public List<Object> FindBugListByResponsibleUserid(List<Object> request)
			throws SQLException, ClassNotFoundException, ParseException {

		response = new ArrayList<Object>();

		String proid = request.get(0).toString();
		String userid = request.get(1).toString();

		BugDAO bugDAO = new BugDAO();
		tmp = bugDAO.findByUserid(proid, userid, usr_responsible);

		bugUserDAO = new BugUserDAO();
		Iterator<Object> iter = tmp.iterator();
		while(iter.hasNext()) {
			Bug b = (Bug) iter.next();

			// bug id
			response.add(EBM.util.BugID.ConvertFromServerToClient(b.getId()));

			// 当前责任人
			User user = new User();
			user = bugUserDAO.findByBugid(proid, b.getId(), usr_responsible);
			response.add(user.getUsrid());
			response.add(user.getName());

			response.add(b.getBug_statu());

			if (b.getSimple_description() != null)
				response.add(b.getSimple_description()); // 概要描述
			else
				response.add("-1");

			// 停留天数
			String days = SystemTime.WaitingDays(b.getCurrent_step_time());
			response.add(days);
		}
		if (tmp.size() < 1)
			response.add("-1");

		return response;
	}

	// 查找缺陷详细信息
	public List<Object> FindBugDetailInfo(List<Object> request)
			throws SQLException, ClassNotFoundException, ParseException {

		bug = new Bug();
		bugUser = new BugUser();
		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));

		// 缺陷相关人员
		BugUserDAO bugUserDAO = new BugUserDAO();
		User userSubmit = bugUserDAO.findByBugid(bug.getProid(), bug.getId(), usr_submit);
		User userCheck = bugUserDAO.findByBugid(bug.getProid(), bug.getId(), usr_check);
		User userLocate = bugUserDAO.findByBugid(bug.getProid(), bug.getId(), usr_locate);
		User userFix = bugUserDAO.findByBugid(bug.getProid(), bug.getId(), usr_fix);
		User userVerify = bugUserDAO.findByBugid(bug.getProid(), bug.getId(), usr_verify);
		if (userSubmit == null)
			bugUser.setUsr_submit("-1");
		else bugUser.setUsr_submit(userSubmit.getUsrid());
		if (userCheck == null)
			bugUser.setUsr_check("-1");
		else bugUser.setUsr_check(userCheck.getUsrid());
		if (userLocate == null)
			bugUser.setUsr_locate("-1");
		else bugUser.setUsr_locate(userLocate.getUsrid());
		if (userFix == null)
			bugUser.setUsr_fix("-1");
		else bugUser.setUsr_fix(userFix.getUsrid());
		if (userVerify == null)
			bugUser.setUsr_verify("-1");
		else bugUser.setUsr_verify(userVerify.getUsrid());

		// 缺陷信息
		Bug b = FindBug(bug.getProid(), bug.getId());

		response = new ArrayList<Object>();

		response.add(bugUser.getUsr_submit()); // 提交人

		response.add(SystemTime.FormatTime(b.getSubmit_time())); // 提交时间

		if (b.getBug_model() != null)
			response.add(b.getBug_model()); // 项目模块
		else
			response.add("");

		if (b.getHard_environment() != null)
			response.add(b.getHard_environment()); // 硬件环境
		else
			response.add("");

		if (b.getSoft_environment() != null)
			response.add(b.getSoft_environment()); // 软件环境
		else
			response.add("");

		response.add(b.getSerious_level()); // 严重程度
		response.add(b.getPriority_level()); // 优先级别

		if (b.getDetail_description() != null)
			response.add(b.getDetail_description()); // 详细描述
		else
			response.add("");

		response.add(b.getReappear()); // 是否重现

		if (b.getReappear_step() != null)
			response.add(b.getReappear_step()); // 重现步骤
		else
			response.add("");

		if (b.getBug_appdix() != null)
			response.add(b.getBug_appdix()); // 附件
		else
			response.add("");

		if (bugUser.getUsr_check() != null) {
			response.add("next");
			response.add(bugUser.getUsr_check()); // 审核人
		} else {
			response.add("shutdown");
			response.add(b.getBug_statu()); // 缺陷状态
		}

		// response.add(b.getBug_statu()); //缺陷状态

		if (b.getCheck_info() != null)
			response.add(b.getCheck_info()); // 审核意见
		else
			response.add("");

		if (bugUser.getUsr_locate() != null) {
			response.add("next");
			response.add(bugUser.getUsr_locate()); // 定位人
		} else {
			response.add("shutdown");
			response.add("");
		}

		if (b.getBug_source() != null)
			response.add(b.getBug_source()); // 缺陷来源
		else
			response.add("");

		if (b.getFix_info() != null)
			response.add(b.getFix_info()); // 修改意见
		else
			response.add("");

		if (bugUser.getUsr_fix() != null) {
			response.add("next");
			response.add(bugUser.getUsr_fix()); // 修改人
		} else {
			response.add("shutdown");
			response.add("");
		}

		if (b.getFix_description() != null)
			response.add(b.getFix_description()); // 修改描述
		else
			response.add("");

		if (b.getFix_description() != null)
			response.add(b.getFix_appdix()); // 修改附件
		else
			response.add("");

		if (bugUser.getUsr_verify() != null) {
			response.add("next"); // 验证人
		} else {
			response.add("shutdown");
			response.add("");
		}

		if (bugUser.getUsr_verify() != null)
			response.add(b.getVerify_pass()); // 验证是否通过
		else
			response.add("0"); // 验证是否通过,默认0,不通过

		return response;
	}

	// 创建缺陷
	public List<Object> newBug(String cmd, List<Object> request)
			throws SQLException, ClassNotFoundException {

		bug = new Bug();
		bugUser = new BugUser();
		bugLog = new BugLog();
		// 当前系统时间
		String time = SystemTime.GetCurrentTime();
		// 当前责任人接受缺陷报告单的时间
		bug.setCurrent_step_time(time);

		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));

		// 提交人
		bugUser.setUsr_submit(request.get(2).toString());
		bugLog.setPerson(request.get(2).toString());

		// 提交时间
		bug.setSubmit_time(request.get(3).toString());
		//bug.setSubmit_time(time);

		bug.setBug_model(request.get(4).toString());
		bug.setHard_environment(request.get(5).toString());
		bug.setSoft_environment(request.get(6).toString());
		bug.setSerious_level(request.get(7).toString());
		// bug.setPriority_level(request.get(8).toString());
		bug.setSimple_description(request.get(8).toString());
		bug.setDetail_description(request.get(9).toString());
		bug.setReappear(request.get(10).toString());
		bug.setReappear_step(request.get(11).toString());
		bug.setBug_appdix(request.get(12).toString());
		String op = request.get(13).toString();
		if (op.equals("next")) { // 指定下一步
			bugUser.setUsr_check(request.get(14).toString());

			if (cmd.equals("newbugsave")) // 保存
				// 缺陷为草稿状态
				bug.setBug_statu(String.valueOf(bug_draft));
			else if (cmd.equals("newbugsubmit")) // 提交
				// 缺陷为新建状态
				bug.setBug_statu(String.valueOf(bug_create));
		} else if (op.equals("shutdown")) { // 关闭缺陷
			bugUser.setUsr_check("");
			// 缺陷为关闭状态的一种
			bug.setBug_statu(request.get(14).toString());
		}

		bugDAO = new BugDAO();
		bugUserDAO = new BugUserDAO();

		Bug b = FindBug(bug.getProid(), bug.getId()); // 查看当前缺陷是否存在

		// 得到人员的id
		UserManage userMan = new UserManage();
		String user_submit_verify_id = userMan.GetId(bugUser.getUsr_submit());
		String user_check_id = "";
		if (op.equals("next"))
			user_check_id = userMan.GetId(bugUser.getUsr_check());

		// 添加或更改缺陷信息
		if (cmd.equals("newbugsave")) {
			if (b == null) {
				// System.out.println("这是保存，是insert");
				// 添加新的缺陷
				bug.setId(bugDAO.save(bug));
				// 添加缺陷相关的人员
				bugUserDAO.save(bug.getProid(), bug.getId(),
						user_submit_verify_id, usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(),
						user_submit_verify_id, usr_submit);
				bugUserDAO.save(bug.getProid(), bug.getId(),
						user_submit_verify_id, usr_verify);
			} else {
				// System.out.println("这是保存，是update");
				// 修改缺陷的信息
				bugDAO.update(bug);
			}
			// 如果指定审核人,删掉已有的，再插入，以作更新
			if (op.equals("next")) {
				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_check);
				bugUserDAO.save(bug.getProid(), bug.getId(), user_check_id,
						usr_check);
			}
			bugLog.setDetail("保存新建缺陷");
		} else if (cmd.equals("newbugsubmit")) {

			if (op.equals("next")) { // 如果提交给审核人，则记录审核人起始时间
				bug.setCurrent_step_time(time);
			} else { // 如果关闭缺陷，则置当前责任人为空
				bugUserDAO.update(bug.getProid(), bug.getId(), "", usr_responsible);
			}

			if (b == null) {
				// System.out.println("这是提交，是insert");
				// 添加新的缺陷
				bug.setId(bugDAO.save(bug));
				// 添加缺陷相关的人员
				bugUserDAO.save(bug.getProid(), bug.getId(), user_check_id,
						usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(),
						user_submit_verify_id, usr_submit);
				bugUserDAO.save(bug.getProid(), bug.getId(),
						user_submit_verify_id, usr_verify);
			} else {
				// System.out.println("这是提交，是update");
				// 修改缺陷的信息
				bugDAO.update(bug);
			}
			// 如果指定审核人,则把当前责任人改为审核人(一定有当前责任人)，并添加审核人（删除已有的，再插入，以作更新）
			if (op.equals("next")) {
				bugUserDAO.update(bug.getProid(), bug.getId(), user_check_id,
						usr_responsible);
				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_check);
				bugUserDAO.save(bug.getProid(), bug.getId(), user_check_id,
						usr_check);
			}
			bugLog.setDetail("提交新建缺陷");
		}

		// 记录日志
		bugLog.setPerson(bugUser.getUsr_submit());
		bugLog.setBugid(bug.getId());
		WriteLog(bug.getProid(), bugLog);

		response = new ArrayList<Object>();
		response.add(EBM.util.BugID.ConvertFromServerToClient(bug.getId()));

		return response;
	}

	// 草稿缺陷提交
	public List<Object> submitDraftBug(String projectName, int bugId) throws SQLException, ClassNotFoundException {
		response = new ArrayList<Object>();
		bugDAO = new BugDAO();
		bugDAO.submitDraftBug(projectName, bugId);
		response.add("ok");
		return response;
	}
	// 审核缺陷
	public List<Object> checkBug(List<Object> request) throws SQLException,
			ClassNotFoundException {
		bug = new Bug();
		bugUser = new BugUser();
		bugLog = new BugLog();

		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));
		String currentUser = request.get(2).toString();
		bug.setPriority_level(request.get(3).toString());
		bug.setCheck_info(request.get(4).toString());
		String op = request.get(5).toString();
		if (op.equals("next"))
			bugUser.setUsr_locate(request.get(6).toString());
		else if (op.equals("shutdown"))
			bug.setBug_statu(String.valueOf(bug_hang));// 挂起

		response = new ArrayList<Object>();
		try {
			bugDAO = new BugDAO();
			String set_clause;
			// 作更新
			set_clause = "set priority_level='" + bug.getPriority_level()
					+ "',check_info='" + bug.getCheck_info() + "'";

			// 人员变更
			if (op.equals("next")) {
				UserManage userMan = new UserManage();
				String user_locate_id = userMan.GetId(bugUser.getUsr_locate());

				bugUserDAO = new BugUserDAO();
				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_locate);
				bugUserDAO.save(bug.getProid(), bug.getId(), user_locate_id,
						usr_locate);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user_locate_id,
						usr_responsible);

				bug.setBug_statu(String.valueOf(bug_locate));// 定位
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("审查缺陷-指定责任人:" + bugUser.getUsr_locate());
			} else if (op.equals("back")) {
				// 得到提交人
				bugUserDAO = new BugUserDAO();
				User user = bugUserDAO.findByBugid(bug.getProid(), bug.getId(),	usr_submit);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user.getId(), usr_responsible);

				bug.setBug_statu(String.valueOf(bug_draft));// 草稿
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("审查缺陷-返回提交人");
			} else if (op.equals("shutdown")) {
				// 作更新
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("审查缺陷-问题单挂起");
			}
			// 执行
			bugDAO.updateBySQL(bug.getProid(), set_clause, bug.getId());

			// 记录日志
			bugLog.setPerson(currentUser);
			bugLog.setBugid(bug.getId());
			WriteLog(bug.getProid(), bugLog);

			response.add("1");
		} catch (SQLException e) {
			response.add("-1");
		}

		return response;
	}

	// 定位缺陷
	public List<Object> LocateBug(List<Object> request) throws SQLException,
			ClassNotFoundException {
		bug = new Bug();
		bugUser = new BugUser();
		bugLog = new BugLog();

		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));
		String currentUser = request.get(2).toString();
		bug.setBug_source(request.get(3).toString());
		bug.setFix_info(request.get(4).toString());
		String op = request.get(5).toString();
		if (op.equals("next"))
			bugUser.setUsr_fix(request.get(6).toString());

		response = new ArrayList<Object>();
		try {
			bugDAO = new BugDAO();
			String set_clause;
			// 作更新
			set_clause = "set bug_source='" + bug.getBug_source()
					+ "',fix_info='" + bug.getFix_info() + "'";

			// 人员变更
			if (op.equals("next")) {
				UserManage userMan = new UserManage();
				String user_fix_id = userMan.GetId(bugUser.getUsr_fix());

				bugUserDAO = new BugUserDAO();
				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_fix);
				bugUserDAO.save(bug.getProid(), bug.getId(), user_fix_id,
						usr_fix);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user_fix_id,
						usr_responsible);

				bug.setBug_statu(String.valueOf(bug_modify));// 修改
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("定位缺陷-修改实施:" + bugUser.getUsr_fix());
			} else if (op.equals("back")) {
				// 得到审核人
				bugUserDAO = new BugUserDAO();
				User user = bugUserDAO.findByBugid(bug.getProid(), bug.getId(),
						usr_check);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user.getId(),
						usr_responsible);

				bug.setBug_statu(String.valueOf(bug_create));// 新建
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("定位缺陷-返回审核人");
			}

			// 执行
			bugDAO.updateBySQL(bug.getProid(), set_clause, bug.getId());

			// 记录日志
			bugLog.setPerson(currentUser);
			bugLog.setBugid(bug.getId());
			WriteLog(bug.getProid(), bugLog);

			response.add("1");
		} catch (SQLException e) {
			response.add("-1");
		}

		return response;
	}

	// 修改缺陷
	public List<Object> FixBug(List<Object> request) throws SQLException,
			ClassNotFoundException {
		bug = new Bug();
		bugUser = new BugUser();
		bugLog = new BugLog();

		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));
		String currentUser = request.get(2).toString();
		bug.setFix_description(request.get(3).toString());
		bug.setFix_appdix(request.get(4).toString());
		String op = request.get(5).toString();

		response = new ArrayList<Object>();
		try {
			bugDAO = new BugDAO();
			String set_clause;
			// 作更新
			set_clause = "set fix_description='" + bug.getFix_description()
					+ "',fix_appdix='" + bug.getFix_appdix() + "'";

			// 人员变更
			if (op.equals("next")) {
				// 得到验证人
				bugUserDAO = new BugUserDAO();
				User user = bugUserDAO.findByBugid(bug.getProid(), bug.getId(),
						usr_verify);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user.getId(),
						usr_responsible);

				bug.setBug_statu(String.valueOf(bug_verify)); // 验证
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("修改缺陷-提交验证人:" + user.getUsrid());
			} else if (op.equals("back")) {
				// 得到定位人
				bugUserDAO = new BugUserDAO();
				User user = bugUserDAO.findByBugid(bug.getProid(), bug.getId(),
						usr_locate);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user.getId(),
						usr_responsible);

				bug.setBug_statu(String.valueOf(bug_locate));// 定位
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("修改缺陷-重新定位");
			}

			// 执行
			bugDAO.updateBySQL(bug.getProid(), set_clause, bug.getId());

			// 记录日志
			bugLog.setPerson(currentUser);
			bugLog.setBugid(bug.getId());
			WriteLog(bug.getProid(), bugLog);

			response.add("1");
		} catch (SQLException e) {
			response.add("-1");
		}

		return response;
	}

	// 验证缺陷
	public List<Object> VerifyBug(List<Object> request) throws SQLException,
			ClassNotFoundException {
		response = new ArrayList<Object>();
		
		//检查传入参数的合法性
		if (request == null || request.size() != 5)
		{
			response.add("-1");
			return response;
		}
		bug = new Bug();
		bugLog = new BugLog();

		bug.setProid(request.get(0).toString());
		bug.setId(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));
		String currentUser = request.get(2).toString();
		bug.setVerify_pass(request.get(3).toString());
		String op = request.get(4).toString();

		try {
			bugDAO = new BugDAO();
			// 作更新
			String set_clause = "set verify_pass='" + bug.getVerify_pass()
					+ "'";

			if (op.equals("back")) {
				// 得到修改人
				bugUserDAO = new BugUserDAO();
				User user = bugUserDAO.findByBugid(bug.getProid(), bug.getId(),
						usr_fix);

				bugUserDAO.delete(bug.getProid(), bug.getId(), usr_responsible);
				bugUserDAO.save(bug.getProid(), bug.getId(), user.getId(),
						usr_responsible);

				bug.setBug_statu(String.valueOf(bug_modify));// 修改
				set_clause += ",bug_statu='" + bug.getBug_statu() + "'";

				bugLog.setDetail("验证缺陷-返回修改人:" + user.getUsrid());
			} else if (op.equals("shutdown")) { // 关闭缺陷
				set_clause += ",bug_statu='" + bug_normal + "'";

				bugLog.setDetail("正常关闭");
			}
			// 执行
			bugDAO.updateBySQL(bug.getProid(), set_clause, bug.getId());

			// 记录日志
			bugLog.setPerson(currentUser);
			bugLog.setBugid(bug.getId());
			WriteLog(bug.getProid(), bugLog);

			response.add("1");
		} catch (SQLException e) {
			response.add("-1");
		}

		return response;
	}

	// 记录日志
	public boolean WriteLog(String proid, BugLog log) throws SQLException,
			ClassNotFoundException {
		// 当前系统时间
		String time = SystemTime.GetCurrentTime();
		bugLog.setTime(time);

		bugLogDAO = new BugLogDAO();
		if (bugLogDAO.save(proid, log))
			return true;
		else
			return false;
	}
}
